/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wudt;

import common.tools;
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.event.ValueChangeEvent;

/**
 *
 * @author jzajaczek
 */
@ManagedBean
@RequestScoped
public class Gasket implements Serializable {
     @ManagedProperty(value="#{medium}")
     protected medium m;
     
     @ManagedProperty(value="#{tools}")
     protected tools to;    

    /**
     * Creates a new instance of Gasket
     */
    public Gasket() {
    }
    
    public Gasket(int i) {}
    
    private String gasketType;
    private static Map<String, Class> gaskets;
    
    private String name = "azbest";
    
    // geometria uszczelki    
    protected double dw = 80.0;
    protected double dz = 120.0;
    private double g = 3.0;
    
    private double u;
    private double ucz;
    private double du;    
    
    // współczynniki uszczelki    
    private double sm = 25.0;
    private double sr = 2.5;
    private double b = 1.1;
    
    // uszczelka - siły
    private double p;
    private double s;
    private double nr;
    private double nm1;
    private double nm2;
    private double n;
    private double c;    
    
    static {
        gaskets = new LinkedHashMap<String, Class>();
        gaskets.put("uszczelka płaska", FlatGasket.class);
        gaskets.put("uszczelka okrągła miękka", RoundSoftGasket.class);
        //gaskets.put("uszczelka okrągła metalowa", RoundMetalGasket);
        //gasketType.put("uszczelka wielokrawędziowa", "Gasket");
        //gasketType.put("uszczelka soczewkowa", "lensGasket");
    }
    
    public void gasketTypeChanged(ValueChangeEvent e){
		gasketType = e.getNewValue().toString();
	}  
    
    public Map<String, Class> getGasket() {
        return this.gaskets;
    }
   
    /**
     * @return the m
     */
    public medium getM() {
        return m;
    }

    /**
     * @param m the m to set
     */
    public void setM(medium m) {
        this.m = m;
    }    

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getDw() {
        return dw;
    }

    public void setDw(double dw) {
        this.dw = dw;
    }

    public double getDz() {
        return dz;
    }

    public void setDz(double dz) {
        this.dz = dz;
    }

    public double getG() {
        return g;
    }

    public void setG(double g) {
        this.g = g;
    }

    public double getSm() {
        return sm;
    }

    public void setSm(double sm) {
        this.sm = sm;
    }

    public double getSr() {
        return sr;
    }

    public void setSr(double sr) {
        this.sr = sr;
    }

    public double getB() {
        return b;
    }

    public void setB(double b) {
        this.b = b;
    }
    
    /**
     * @return the P
     */
    public double getP() {
        double du_ = getDu();
        double po_ = m.getPo();
        double f_ = getTo().getN_kN();
        return getTo().round(f_ * (0.25 * Math.PI * Math.pow(du_, 2) * po_),2);
    }
    
    /**
     * @return the s
     */
    public double getS() {
        double du_ = getDu();
        double ucz_ = getUcz();
        double Sr_ = sr;
        double po_ = m.getPo();
        return getTo().round(0.001 * (Math.PI * du_ * ucz_ * Sr_ * po_), 2);
    }

    /**
     * @return the nr
     */
    public double getNr() {
        double P_ = m.getPo();
        double b_ = getB();
        double S_ = getS();
        return getTo().round(P_ + b_ * S_,2);
    }    
    
    /**
     * @return the nm1
     */
    public double getNm1() {
        double du_ = getDu();
        double ucz_ = getUcz();
        double Sm_ = sm;
        return getTo().round(0.001 *(Math.PI * du_ * ucz_ * Sm_),2);
    }

    /**
     * @return the nm2
     */
    public double getNm2() {
        double C_ = getC();
        double Nr_ = getNr();
        return getTo().round(C_ * Nr_,2);
    }    
    
    /**
     * @return the n
     */
    public double getN() {
        double Nr_ = getNr();
        double Nm1_ = getNm1();
        double Nm2_ = getNm2();
        return getTo().round(Math.max(Math.max(Nm1_, Nm2_), Nr_),2);
    }

    /**
     * @return the c
     */
    public double getC() {
        double du_ = getDu();
        if (du_ <= 500.0) {
            return 1.2;
        }
        else {
            return 1.4;
        }
    }    
    
    /**
     * @return the u
     */
    public double getU() {
        return u;
    }

    /**
     * @param du the du to set
     */
    public void setU(double u) {
        this.u = u;
    }    

    /**
     * @return the u
     */
    public double getDu() {
        return du;
    }

    /**
     * @param du the du to set
     */
    public void setDu(double du) {
        this.du = du;
    }

    /**
     * @return the ucz
     */
    public double getUcz() {
        return ucz;
    }

    /**
     * @param ucz the ucz to set
     */
    public void setUcz(double ucz) {
        this.ucz = ucz;
    }

    public tools getTo() {
        return to;
    }

    public void setTo(tools to) {
        this.to = to;
    }

    public String getGasketType() {
        return gasketType;
    }

    public void setGasketType(String gasketType) {
        this.gasketType = gasketType;
    }
    
}